package c.e.a.c.x;

import android.text.Editable;
import android.text.TextWatcher;
import android.text.method.PasswordTransformationMethod;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.EditText;
import com.google.android.material.textfield.TextInputLayout;
import com.google.android.material.textfield.TextInputLayout.f;
import com.google.android.material.textfield.TextInputLayout.g;
import com.huawei.hms.analytics.core.crypto.AesCipher.AesLen;

/* compiled from: PasswordToggleEndIconDelegate */
public class q extends m {
    public final TextWatcher d = new a();
    public final f e = new b();
    public final g f = new c();

    /* compiled from: PasswordToggleEndIconDelegate */
    public class a implements TextWatcher {
        public void afterTextChanged(Editable editable) {
        }

        public void beforeTextChanged(CharSequence charSequence, int i, int i2, int i3) {
            q qVar = q.this;
            qVar.c.setChecked(q.e(qVar) ^ 1);
        }

        public void onTextChanged(CharSequence charSequence, int i, int i2, int i3) {
        }
    }

    /* compiled from: PasswordToggleEndIconDelegate */
    public class d implements OnClickListener {
        public void onClick(View view) {
            EditText editText = q.this.a.getEditText();
            if (editText != null) {
                int selectionEnd = editText.getSelectionEnd();
                if (q.e(q.this)) {
                    editText.setTransformationMethod(null);
                } else {
                    editText.setTransformationMethod(PasswordTransformationMethod.getInstance());
                }
                if (selectionEnd >= 0) {
                    editText.setSelection(selectionEnd);
                }
            }
        }
    }

    /* compiled from: PasswordToggleEndIconDelegate */
    public class b implements f {
        public void a(TextInputLayout textInputLayout) {
            EditText editText = textInputLayout.getEditText();
            textInputLayout.setEndIconVisible(true);
            textInputLayout.setEndIconCheckable(true);
            q qVar = q.this;
            qVar.c.setChecked(q.e(qVar) ^ 1);
            editText.removeTextChangedListener(q.this.d);
            editText.addTextChangedListener(q.this.d);
        }
    }

    /* compiled from: PasswordToggleEndIconDelegate */
    public class c implements g {
        public void a(TextInputLayout textInputLayout, int i) {
            EditText editText = textInputLayout.getEditText();
            if (editText != null && i == 1) {
                editText.setTransformationMethod(PasswordTransformationMethod.getInstance());
                editText.removeTextChangedListener(q.this.d);
            }
        }
    }

    public q(TextInputLayout textInputLayout) {
        super(textInputLayout);
    }

    public static boolean e(q qVar) {
        EditText editText = qVar.a.getEditText();
        return editText != null && (editText.getTransformationMethod() instanceof PasswordTransformationMethod);
    }

    public void a() {
        this.a.setEndIconDrawable(b.b.d.a.a.b(this.b, 2131230962));
        TextInputLayout textInputLayout = this.a;
        textInputLayout.setEndIconContentDescription(textInputLayout.getResources().getText(2131690166));
        this.a.setEndIconOnClickListener(new d());
        this.a.a(this.e);
        this.a.g0.add(this.f);
        EditText editText = this.a.getEditText();
        Object obj = (editText == null || !(editText.getInputType() == 16 || editText.getInputType() == AesLen.ROOTKEY_COMPONET_LEN || editText.getInputType() == 144 || editText.getInputType() == 224)) ? null : 1;
        if (obj != null) {
            editText.setTransformationMethod(PasswordTransformationMethod.getInstance());
        }
    }
}
